package core.dto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import exceptions.UserNotFoundException;

public class Database implements IDatabase {

	private Map<Integer, IOperatorDTO> userMap = new HashMap<Integer, IOperatorDTO>();

	@Override
	public IOperatorDTO getUser(int ID) throws UserNotFoundException {

		if (userMap.get(ID) == null) {
			throw new UserNotFoundException(ID);
		}

		else{
			return userMap.get(ID);
		}

	}

	@Override
	public List getUserList() {
		List<IOperatorDTO> temp = new ArrayList<IOperatorDTO>(userMap.values());
		return temp;
	}

	@Override
	public void add(IOperatorDTO user) {
		userMap.put(user.getOprId(), user);

	}

	@Override
	public void remove(int ID) throws UserNotFoundException {
		if (userMap.get(ID) == null)
			throw new UserNotFoundException(ID);
		
		else
			userMap.remove(ID);

	}

}
